package com.itheima.service.iml;

import com.itheima.bean.DishFlavor;
import com.itheima.common.R;
import com.itheima.dao.DishDao;
import com.itheima.dao.DishFlavorDao;
import com.itheima.dto.DishDto;
import com.itheima.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tang
 * @date 2022/11/23 16:44
 */
@Service
public class DishServiceImpl implements DishService {
    @Autowired
    private DishDao dishDao;
    @Autowired
    private DishFlavorDao dishFlavorDao;

    @Override
    public R<String> add(DishDto dishDto) {
        //将dish数据保存到数据库
        dishDao.add(dishDto);
        //将DishFlavor数据保存到数据
        List<DishFlavor> dishFlavors = dishDto.getDishFlavors();
        for (DishFlavor dishFlavor : dishFlavors) {
            dishFlavorDao.add(dishFlavor);
        }
        return R.success("保存成功");
    }
}
